package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.auxgroup.hr.front.service.hireperson.impl.HireEducatServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModTrain;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModTrainRepository;
import com.auxgroup.hr.front.service.modperson.ModTrainService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 培训经历流程信息service
 */
@Service("modTrainService")
public class ModTrainServiceImpl implements ModTrainService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCModTrainRepository PsCModTrainRepository;


	@Override
	public PsCModTrain getModTrain(PsCModPerPrimary modPerPrimary) {
		return PsCModTrainRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModTrain save(PsCModTrain ModTrain,UserDTO user) {
		ModTrain.setHrsRowAddOprid(user.getOprId());
		ModTrain.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModTrain.setHrsRowUpdOprid(user.getOprId());
		ModTrain.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModTrain,ignoreFields);
		return PsCModTrainRepository.save(ModTrain);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModTrainRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModTrain error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModTrain> getAll(String emplid) {
		PsCModTrain ModTrain = new PsCModTrain();
		ModTrain.setEmplid(emplid);
		return PsCModTrainRepository.findAll(Example.of(ModTrain));
	}


	/* (non-Javadoc)
	 * @see ModTrainService#getAll(java.lang.String, java.lang.String)
	 */
	@Override
	public List<PsCModTrain> getAll(String cTransactionNbr, String emplid) {
		PsCModTrain ModTrain = new PsCModTrain();
		ModTrain.setEmplid(emplid);
		ModTrain.setcTransactionNbr(cTransactionNbr);
		return PsCModTrainRepository.findAll(Example.of(ModTrain));
	}


	
	
	
}
